import unittest
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from unit__003.unit_01.Mysql import Mysql
from unit__003.unit_01.Tools import Tools
from unit__003.unit_01.Mysql import Mysql


class A3mall(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')
        Tools().Log()
        self.db = Mysql(host='10.59.9.12', user='root', password='yidong666', database='a3mall')
        self.driver = webdriver.Edge()
        self.driver.get('http://10.59.9.12:7001/admin/')
        self.driver.maximize_window()

    def tearDown(self) -> None:
        print('end case')
        sleep(5)
        self.driver.quit()

    def test_01(self):
        sleep(2)
        # 输入账号
        self.driver.find_element(By.NAME, 'username').send_keys('admin')
        sleep(2)
        # 输入密码
        self.driver.find_element(By.NAME, 'password').send_keys('admin888')
        sleep(10)
        # 点击登录
        self.driver.find_element(By.XPATH, '/html/body/div[2]/div/div/form/div[4]/button').click()
        sleep(5)
        # # 点击会员
        # self.driver.find_element(By.XPATH, '/html/body/div/header/nav/div[1]/ul/li[5]/a').click()
        # sleep(2)
        # # 搜索框输入搜索内容
        # search = self.driver.find_element(By.XPATH, '//*[@id="search-box"]/div/div/form/div/div[2]/div/input')
        # search.send_keys('18185607777')
        # sleep(2)
        # # 点击搜索
        # self.driver.find_element(By.ID, 'search-btn').click()
        # sleep(2)
        # # 提取用户名进行数据库断言
        # dy1 = self.driver.find_element(By.XPATH,
        #                                '/html/body/div/div/section/div/div/div[2]/div[2]/table/tbody/tr/td[3]/div').text
        # print('断言1：', dy1)
        # # 提取用户余额进行数据库断言
        # dy2 = self.driver.find_element(By.XPATH,
        #                                '/html/body/div/div/section/div/div/div[2]/div[2]/table/tbody/tr/td[6]/div').text
        # print('断言2：', dy2)
        # result = self.db.chaxun(f'select * from mall_users where id={"338"}')
        # print(result)
        # self.assertEqual(dy1, result[0][6])
        # sleep(2)
        # print(result[0][20])
        # self.assertTrue(float(dy2) == result[0][20])


if __name__ == '__main__':
    unittest.main()
